graph representation and traversal algorithms in python